package homework;

import util.Util;
import jdk.dynalink.linker.GuardedInvocationTransformer;

import javax.transaction.xa.Xid;
import java.util.*;
import java.util.List;
import java.util.stream.Collector;
import javax.swing.*;
import java.awt.*;

public class Pokeroom extends JFrame {
    private Image bgimg = Util.getImage("/img/bg.jpeg");
    private ArrayList<Card> list = new ArrayList<Card>();
    private String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
    private String[] flowers = {"♠", "❤", "♣", "♦"};
    private List one =new ArrayList() ;
    private List two =new ArrayList() ;
    private List three =new ArrayList() ;
    private List bottom =new ArrayList() ;

    //初始化
    public void init() {
        for (int i = 0; i < points.length; i++) {
            for (int j = 0; j < flowers.length; j++) {
                //将带花色的扑克牌加入集合
                list.add(new Card(points[i], flowers[j], i, "/img/" + (i + 3) + "_" + (j + 1) + ".jpg"));
            }
        }
        list.add(new Card("小王", null, 50, "/img/16_1.jpg"));
        list.add(new Card("大王", null, 99, "/img/17_1.jpg"));
        System.out.println(list);
    }

    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    public void fapai() {
        one = list.subList(0, 17);
        one.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        two = list.subList(17, 34);
        two.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getValue() - o1.getValue();
            }
        });
        three = list.subList(34, 51);
        three.sort(new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o2.getValue() - o1.getValue();
            }
        });
         bottom = list.subList(51, 54);
        System.out.println(one);
        System.out.println(two);
        System.out.println(three);
        System.out.println(bottom);




    }
//


    public Pokeroom() {
        this.init();
        this.xipai();
        this.fapai();
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgimg, 0, 0, 1200, 1200, this);
            }
        });
        this.setLayout(null);
        for (int i =0;i<one.size();i++){
        JLabel label = new JLabel( Util.getIcon(one.get(i).toString()));
       label.setBounds(20,540-i*30,105,150);
        this.add(label);
        }
        for (int i =0;i<two.size();i++){
            JLabel label = new JLabel( Util.getIcon(two.get(i).toString()));
            label.setBounds(660-i*30,540,105,150);
            this.add(label);
        }
        for (int i =0;i<three.size();i++){
            JLabel label = new JLabel( Util.getIcon(three.get(i).toString()));
            label.setBounds(800,540-i*30,105,150);
            this.add(label);
        }
        for (int i =0;i<bottom.size();i++){
            JLabel label = new JLabel( Util.getIcon(bottom.get(i).toString()));
            label.setBounds(500-i*30,300,105,150);
            this.add(label);
        }
        this.setSize(1000, 1400);//设置宽度
        this.setTitle("测试窗口");//设置标题
        this.setIconImage(Util.getImage("/img/ddd.png"));//图标
        this.setLocationRelativeTo(null);//设置窗口居中
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口关闭时程序结
        this.setVisible(true);//设置窗体可见
    }


    public static void main(String[] args) {
        Pokeroom a = new Pokeroom();

    }

}
